package com.relatev.minecraft.TRMExample;

import com.relatev.minecraft.TRMobAPI.TRJsonConfigurable;
import com.relatev.minecraft.TRMobAPI.TRLevelMob;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;

public class TestZombie extends TRLevelMob implements TRJsonConfigurable {

    public TestZombie() {
        super("&a小绿 &bLv.%Level%", EntityType.ZOMBIE); //%Level%代表着该怪物的等级
    }

    @Override
    public LivingEntity spawn(Location loc, int level) {
        Zombie zombie = (Zombie) super.spawn(loc, level);
        zombie.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20 + level * 5); //设定怪物出生最大生命值为 20+等级x5
        zombie.setHealth(zombie.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); //让怪物满血
        return zombie;
    }

    @EventHandler
    public void onDamage(EntityDamageByEntityEvent event) {
        if (super.isThisMob(event.getDamager())) { //如果攻击者是我们设计的怪物
            Zombie zombie = (Zombie) event.getDamager();
            event.setDamage(super.getLevel(zombie) * 2D); //设定怪物伤害为 等级x2
        }
    }

    @EventHandler(priority = EventPriority.HIGH)
    public void onDeathDrop(EntityDeathEvent event) {
        if (super.isThisMob(event.getEntity())) {
            LivingEntity lent = event.getEntity();
            event.setDroppedExp(super.getLevel(lent) * 2); //设定怪物掉落经验为 等级x2
            if (super.getLevel(lent) > 5) {
                event.getDrops().add(new ItemStack(Material.DIAMOND)); //如果怪物等级超过5 掉一颗钻石
            }
        }
    }
}
